Skip to content

Add /mcp update command to reload MCP servers without restart#1

Merged
dzarlax merged 1 commit into
mainfrom
claude/add-mcp-update-command-76JJK
Mar 18, 2026
Merged

Add /mcp update command to reload MCP servers without restart#1
dzarlax merged 1 commit into
mainfrom
claude/add-mcp-update-command-76JJK

Conversation

@dzarlax

@dzarlax dzarlax commented Mar 18, 2026

Copy link
Copy Markdown
Collaborator

∙ MCP Client (internal/mcp/client.go): add Reconnect() method — closes existing connections, rebuilds servers from new config, re-initializes, and re-embeds tools
∙ Agent (internal/agent/agent.go): add ReloadMCP() proxy method to expose reconnect to the handler layer
∙ Telegram (internal/telegram/handler.go): add /mcp update command (alias /mcp reload) — re-reads config/mcp.json and reconnects all MCP servers on the fly


Note

Medium Risk
Adds runtime MCP reconnection and config reload, which touches external service connectivity and tool discovery/embedding state; failures could temporarily drop tools or change tool availability mid-session.

Overview
Adds a runtime MCP reload path so MCP server configuration can be updated without restarting the bot.

The MCP client now supports Reconnect() to close existing HTTP pools, rebuild server state from a new mcp.json config, re-run tool discovery, and re-embed tools when embeddings are enabled. This is exposed via Agent.ReloadMCP(), and the Telegram bot adds a new /mcp update (alias /mcp reload) command that reloads config/mcp.json, reconnects servers with a timeout, and reports the resulting tool count.

Written by Cursor Bugbot for commit 791dab8. This will update automatically on new commits. Configure here.

- MCP Client: add Reconnect() method that closes old connections,
  rebuilds servers from new config, re-initializes, and re-embeds tools
- Agent: add ReloadMCP() to expose reconnect to the handler layer
- Telegram: add /mcp command with "update"/"reload" subcommands
  that re-reads config/mcp.json and reconnects all MCP servers

https://claude.ai/code/session_01VtMjyBkcnrX8AZDuPj67XT
@dzarlax dzarlax merged commit 7b5072b into main Mar 18, 2026
2 checks passed
@dzarlax dzarlax deleted the claude/add-mcp-update-command-76JJK branch March 18, 2026 20:40

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread internal/mcp/client.go
}

return len(c.tools), nil
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concurrent map access causes fatal runtime panic

High Severity

Reconnect writes to c.servers, c.toolServers, and c.tools without any synchronization. The Telegram handler dispatches up to 10 updates concurrently in goroutines, so a /mcp update command can race with a user message that reads these same maps via CallTool or LLMToolsForQuery. In Go, concurrent read+write on a map is a fatal runtime panic — not just a data race.

Additional Locations (1)
Fix in Cursor Fix in Web

Comment thread internal/mcp/client.go
}
}
c.servers[name] = srv
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated server-building logic in Reconnect and NewClient

Low Severity

The server construction loop in Reconnect (URL validation, server struct creation, allow/deny tool maps) is a near-exact copy of NewClient. Duplicating this logic means future changes (e.g., new server fields or validation rules) need to be applied in both places, risking inconsistent behavior.

Additional Locations (1)
Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants